package com.qyhl.webtv.module_news.news.goodlife;


import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.NewsBean;
import com.qyhl.webtv.module_news.common.NewsUrl;

import java.util.List;

/**
 * Created by qyhl on 2017/11/24.
 */

public class GoodLifeModel implements GoodLifeContract.GoodLifeModel {
    private GoodLifePresenter mPresenter;

    public GoodLifeModel(GoodLifePresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    /**
     * 头部信息
     */
    @Override
    public void getHeaderData() {

        EasyHttp.get(NewsUrl.GET_LIFE_TOP)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .execute(new SimpleCallBack<List<NewsBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.headError();
                    }

                    @Override
                    public void onSuccess(List<NewsBean> newsBeans) {
                        if(newsBeans!=null&&newsBeans.size()>0){
                            mPresenter.headSuccess(newsBeans);
                        }else{
                            mPresenter.headError();
                        }
                    }
                });

    }

    /**
     * 最新内容
     */
    @Override
    public void getBodyData() {
        
        EasyHttp.get(NewsUrl.GET_LIFE_NEWS)
                .execute(new SimpleCallBack<List<NewsBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.bodyError(2, "信息异常，加载出错！");
                    }

                    @Override
                    public void onSuccess(List<NewsBean> newsBeans) {
                        if (newsBeans == null || newsBeans.size() < 1) {
                            mPresenter.bodyError(1, "暂无推荐内容！");
                        } else {
                            mPresenter.bodySuccess(newsBeans);
                        }
                    }
                });
    }
}
